home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / text / edit / tecoc-146.lha / popmac.c < prev    next >
C/C++ Source or Header  |  1991-07-05  |  2KB  |  61 lines

  1. /*****************************************************************************
  2.  
  3.     PopMac()
  4.  
  5.     This function "pops" the current macro environment,  which was
  6. established by an earlier call to the PshMac function.  Part of this job
  7. is de-allocating memory consumed by local q-registers.
  8.  
  9. *****************************************************************************/
  10.  
  11. #include "zport.h"        /* define portability identifiers */
  12. #include "tecoc.h"        /* define general identifiers */
  13. #include "defext.h"        /* define external global variables */
  14.  
  15. DEFAULT PopMac()        /* restore environment after macro exit */
  16. {
  17.     WORD    i;
  18.     MSptr    MSp;        /* pointer into the macro stack */
  19.     QRptr    QRp;        /* pointer into local Q-register table */
  20.     BOOLEAN    RetVal;        /* TRUE if macro is returning a value */
  21.  
  22.     DBGFEN(1,"PopMac",NULL);
  23.  
  24.     RetVal = (EStTop > EStBot);
  25.     if (RetVal) {        /* if macro is returning a value */
  26.         if (GetNmA() == FAILURE) {
  27.         DBGFEX(1,DbgFNm,"FAILURE, GetNmA() failed");
  28.         return FAILURE;
  29.     }
  30.     }
  31.  
  32. /*
  33.  * restore old environment
  34.  */
  35.  
  36.     MSp = &MStack[MStTop];
  37.     CStBeg = MSp->CStBeg;        /* restore old command string start */
  38.     CBfPtr = MSp->CBfPtr;        /* restore old command string ptr */
  39.     CStEnd = MSp->CStEnd;        /* restore old command string end */
  40.     EStBot = MSp->EStBot;        /* restore expression stack bottom */
  41.     EStTop = MSp->EStTop;        /* restore expression stack top */
  42.     LStBot = MSp->LStBot;        /* restore loop stack bottom */
  43.     LStTop = MSp->LStTop;        /* restore loop stack top */
  44.     if (MSp->QRgstr != NULL) {        /* local q-registers allocated? */
  45.         for (QRp = MSp->QRgstr, i = 0; i < 36; ++i, ++QRp) {
  46.         if (QRp->Start != NULL) {
  47.         ZFree((voidptr)QRp->Start);
  48.         }
  49.     }
  50.     ZFree(MSp->QRgstr);
  51.     }
  52.     --MStTop;
  53.  
  54. #if DEBUGGING
  55.     sprintf(DbgSBf,"%s", (RetVal) ? "PushEx(NArgmt)" : "SUCCESS");
  56.     DbgFEx(1,DbgFNm,DbgSBf);
  57. #endif
  58.  
  59.     return ((RetVal) ? PushEx(NArgmt, OPERAND) : SUCCESS);
  60. }
  61.